var express = require('express')
var router = express.Router()

router.use(function timeLog(req, res, next) {
    console.log('Time: ', Date.now())
    next()
})
// define the home page route
router.get('/', function (req, res) {
    //获取 cookie
    var name = req.session.name;
    res.send('首页-用户名：' + name);
})
// define the about route
router.get('/login', function (req, res) {

    var list = [
        { title: '标题1', ttime: '2021-1-10' },
        { title: '标题2', ttime: '2021-1-10' },
        { title: '标题3', ttime: '2021-1-10' },
        { title: '标题4', ttime: '2021-1-10' },
        { title: '标题5', ttime: '2021-1-10' },
    ]

    var h3 = "<h3>这是一个大的文字</h3>"
    //req.session.name = 'admin';  //
    res.render('index.html', { username: '小李', list: list, h3: h3, title: '    abcd    ' });
    //let template = ejs.compile('index.html', { username: '小李', list: list, h3: h3 });

    // expresss  => "<span style='color:red'>express</span>"
    //res.send(template);
})

router.get('/loginout', function (req, res) {
    //删除cookie
    if (req.session.name) {
        req.session.name = '';
    }

    res.send('退出登录')
})

router.get('/edit', function (req, res) {
    var name = req.cookies.name;
    res.send('用户名:' + name);
})

module.exports = router